﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Timer = System.Windows.Forms.Timer;

namespace 第三次作业
{
    internal class Alarm
    {
        private Timer _timer;

        public DateTime AlarmTime { get; set; }

        public event EventHandler<ClockEvent> alarm;

        public void Start()
        {
            _timer = new Timer();
            _timer.Interval = 1000;
            _timer.Tick += Timer_Tick;
            _timer.Start();
        }

        public void Stop()
        {
            _timer.Stop();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now >= AlarmTime)
            {
                alarm?.Invoke(this, new ClockEvent());
                _timer.Stop();
            }
        }
    }
}
